home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Connection Tool ƒ / Validation.c < prev    next >
C/C++ Source or Header  |  1994-02-19  |  3KB  |  93 lines

  1. // ===========================================================================
  2. // "Connection Tool Skeleton in C" for the Communications Toolbox
  3. // 
  4. //    Copyright © 1994 Peter J. Creath
  5. //    All Rights Reserved Worldwide
  6. // ===========================================================================
  7.  
  8. #include "ConnToolCommon.h"
  9.  
  10. // ===========================================================================
  11. // Function prototypes
  12. // ===========================================================================
  13. extern pascal long    main(ConnHandle hConn, short msg, ConfigPtr *hConfig, long allocate, long procID);
  14. extern long    DoValidate(ConnHandle hConn);
  15. extern void    DoDefault(ConfigPtr *hConfig, Boolean allocate);
  16.  
  17. // ===========================================================================
  18. // main()
  19. //     This function is the entry point for the 'cval' resource.  It passes control to the appropriate
  20. //     subroutines, depending on the incoming message.  This can probably remain unchanged.
  21. // ===========================================================================
  22.  
  23. pascal long main(ConnHandle hConn, short msg, ConfigPtr *hConfig, long allocate, long procID)
  24. {
  25. long            rtnValue;
  26.  
  27.     switch (msg)
  28.         {
  29.             case cmValidateMsg:                        // hConn is valid here -- check its configuration
  30.                 rtnValue = DoValidate(hConn);
  31.                 break;
  32.                 
  33.             case cmDefaultMsg:                        // hConn is not valid here -- allocate and set up the default configuration
  34.                 DoDefault(hConfig, allocate);
  35.                 rtnValue = FALSE;                        // IM-CTB doesn't mention what this should be...
  36.                 break;
  37.             
  38.             default:
  39.                 rtnValue = cmNotSupported;
  40.         }
  41.  
  42. return (rtnValue);
  43. }
  44.  
  45. // ===========================================================================
  46. // DoValidate()
  47. //     This function is called in response to a cmValidateMsg.  It should check a currently valid
  48. //     connection to make sure its configuration is OK.  It returns TRUE if it's OK, and FALSE if not.
  49. // ===========================================================================
  50.  
  51. long    DoValidate(ConnHandle hConn)
  52. {
  53. ConfigPtr        pConfig;
  54. long                rtnValue = FALSE;
  55.  
  56.     pConfig = (ConfigPtr)((*hConn)->config);            // Dereference the configuration record
  57.     if (pConfig->foobar == 0)
  58.         rtnValue = FALSE;                                            // It's OK
  59.     else
  60.         {
  61.             DoDefault(&pConfig, FALSE);                        // It's bad -- rebuild it
  62.             rtnValue = TRUE;
  63.         }
  64. }
  65.  
  66. // ===========================================================================
  67. // DoDefault()
  68. //     This subroutine is called in response to a cmDefaultMsg or an invalid ConfigRecord.  It should
  69. //     allocate the memory for the ConfigRecord if requested, and should fill in the configuration with
  70. //    the default data.
  71. // ===========================================================================
  72.  
  73. void    DoDefault(ConfigPtr *hConfig, Boolean allocate)
  74. {
  75. ConfigPtr    pConfig;
  76.  
  77.     if (allocate)        // Allocate the memory for our ConfigRecord
  78.         {
  79.             pConfig = (ConfigPtr)NewPtr(sizeof(ConfigRecord));
  80.             *hConfig = pConfig;
  81.             // You should probably check for errors here, but Inside Mac CommToolbox doesn't
  82.             // mention how you should handle them... 
  83.         }
  84.     else                    // Use the existing ConfigRecord
  85.         {
  86.             pConfig = *hConfig;
  87.         }
  88.  
  89.     // Fill in the default data here
  90.     pConfig->foobar = 0;
  91.     // etc.
  92. }
  93.